package com.lzh.persevere.service.impl;

import cn.hutool.core.collection.CollectionUtil;
import cn.hutool.core.util.StrUtil;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.lzh.persevere.common.BaseEntity;
import com.lzh.persevere.mapper.PhotoWallMapper;
import com.lzh.persevere.model.entity.FileInfo;
import com.lzh.persevere.model.entity.PhotoWall;
import com.lzh.persevere.model.qo.PageModelQO;
import com.lzh.persevere.model.ro.photoWall.AddPhotoWallRO;
import com.lzh.persevere.service.PhotoWallService;
import com.lzh.persevere.template.PageAbstractTemplate;
import org.springframework.stereotype.Service;

import java.util.*;
import java.util.stream.Collectors;

/**
 * 照片墙表服务实现类
 *
 * @author luzhiheng
 * @since 2025-08-09
 */
@Service
public class PhotoWallServiceImpl extends ServiceImpl<PhotoWallMapper, PhotoWall> implements PhotoWallService {

    @Override
    public Boolean addPhotoWallBatch(AddPhotoWallRO ro) {
        List<PhotoWall> photoWallList = ro.getUrlList().stream().map(e -> PhotoWall.builder().url(e).build()).collect(Collectors.toList());
        return this.saveBatch(photoWallList);
    }

    @Override
    public Map<String, Object> findPhotoWallPageList(PageModelQO qo) {
        Map<String, Object> otherQueryMap = Collections.emptyMap();
        PageAbstractTemplate template = new PageAbstractTemplate() {
            @Override
            public Integer countTotal() {
                return baseMapper.countList(this.getQueryMap(qo.getPageModel(), otherQueryMap));
            }

            @Override
            public List<Map<String, Object>> queryPageList() {
                return baseMapper.pageList(this.queryMap);
            }
        };
        return template.queryPage();
    }
}
